﻿using ConfExpert.Utility;
using DevExpress.Utils.Paint;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using Extensions;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;


namespace ConfOrder.Articles
{
    public partial class ArticleOrderReport : XForm
    {
        public ArticleOrderReport()
        {
            InitializeComponent();
        }

        private void POOzetV2_Load(object sender, EventArgs e)
        {
            MainToolbar.Visible = true;
            this.Cursor = Cursors.WaitCursor;

            DataSet ds = AppSession.DataManager.ExecuteDataSet("COGetKumasSiparisTakip", 90);


            gvAyrimlar.Init(ds.Tables[0]);
            //gvAyrimlar.SetViewCaption("Article Orders");

            gvAyrimlar.MakeColumnInvisible("AyrimlarId");

            gvAyrimlar.SetCaptions("POLinesId:#",
                                    "PONr:PO Nr.",
                                    "SiparisTarihi:Order Date",
                                    "PODurumId:Status",
                                    "Scan:Scan",
                                    "VendorId:Vendor",
                                    "CadHl:Requests",
                                    "TalepTarihi:Request Date",
                                    "ProductId:Article",
                                    "Artikel:Article",
                                    "QtyTalep:Requested Qty",
                                    "ToplamYuklenenMt:Shipped Qty",
                                    "ToplamYuklemeAdedi:Shipment Count",
                                    "ToplamGelenMt:Arrived Qty",
                                    "ToplamGelisPartisiAdedi:Arrival Count",
                                    "ToplamKonfirmeMt:Confirmed Qty",
                                    "ToplamKonfirmasyonAdedi:Confirmation Count",
                                    "SKTeknikOzellik:Technical Specs.",
                                    "TalepTeknikOzellik:Requested Technical Specs.",
                                    "BrandId:Brand",
                                    "SezonId:Season",
                                    "OrderRef:Order Ref.",
                                    "MusteriKodu:Customer Code",
                                    "UreticiKodu:Vendor Code",
                                    "Notes:CM Notes",
                                    "VendorNotes:Vendor Notes",
                                    "CadNo:Cad No",
                                    "KstCategoryId:KST Kategori",
                                    "KabulTarihi:Kabul Tarihi",
                                    "CurrencyId:Parabirimi",
                                    "RedSebebi:Red Sebebi",
                                    "YikamaRecetesi:Yıkama Reçetesi",
                                    "BirimMetraj:Birim Metraj",
                                    "GomlekAdedi:Gömlek Adedi",
                                    "UreticiSipNo:Üretici Sip.No.",
                                    "CarrierId:Kargo",
                                    "UserId:Kullanıcı",
                                    "GomlekTermini:Shirt Due Date",
                                    "KumasTermini:Article Due Date",
                                    "TerminNotu:Due Date Notes",
                                    "GerShipments:Shipments",
                                    "OngYuklemeler:Öng. Yüklemeler",
                                    "AnlasilanFiyat:Price",
                                    "PaymentTermId:Ödeme Termini",
                                    "PaymentMethodId:Ödeme Şekli",
                                    "POLOngShipMethodId:POL Öng. Yükleme Şekli",
                                    "POLOngETD:POL Öng. ETD",
                                    "calcETA:ETA",
                                    "PONotes:PO Notes",
                                    "EFOrani:Missing/Over",
                                    "SiraNo:Order",
                                    "KalanMt:Missing Qty",
                                    "FiyatKontrol:Price"
                                    );

            gvAyrimlar.MakeColumnInvisible("ToplamYuklemeAdedi", "ToplamGelisPartisiAdedi", "ToplamKonfirmasyonAdedi", "ProductId", "POLOngShipMethodId", "POLOngETD", "TalepTeknikOzellik");

            gvAyrimlar.FormatAsDate("GomlekTermini", "KumasTermini");
            gvAyrimlar.FormatAsNumber(2, "QtyTalep", "ToplamYuklenenMt", "ToplamGelenMt", "ToplamKonfirmeMt", "FiyatKontrol");
            gvAyrimlar.FormatAsNumber(3, "EFOrani");


            gvAyrimlar.MakeReadOnly();

            GridFormatRule gridFormatRuleY = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBarY = new FormatConditionRuleDataBar();
            gridFormatRuleY.Column = gvAyrimlar.Columns["EFOrani"];
            formatConditionRuleDataBarY.PredefinedName = "Green Gradient";
            gridFormatRuleY.Rule = formatConditionRuleDataBarY;
            gvAyrimlar.FormatRules.Add(gridFormatRuleY);

            gvAyrimlar.Columns["VendorId"].ColumnEdit = RepositoryManager.riVendor;
            gvAyrimlar.Columns["PODurumId"].ColumnEdit = RepositoryManager.riPODurum;
            gvAyrimlar.Columns["Currency"].ColumnEdit = RepositoryManager.riCurrency;
            gvAyrimlar.Columns["PaymentMethod"].ColumnEdit = RepositoryManager.riPaymentMethod;


            gvAyrimlar.BestFitColumns();
            this.Cursor = Cursors.Default;
        }

        private void btnGuncelle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DataSet ds = AppSession.DataManager.ExecuteDataSet("COGetKumasSiparisTakip", 90);
            gvAyrimlar.VeriyiGuncelle(ds.Tables[0]);

        }         
    }
}
